<template>
	<view class="container">
		<view class="address-wrapper" v-if="details.orderRefund.address">
			<view class="address">{{details.orderRefund.address}}</view>
			<view class="name-tel">{{details.orderRefund.name}} {{details.orderRefund.mobile}}</view>	
		</view>
		<view class="product" v-for="product in details.items" :key="product.productId">
			<image :src="product.productImage" mode="aspectFill" class="img"></image>
			<view class="text">
				<view class="name ell">{{product.productName}}</view>
				<view class="specifications ell" v-if="product.normal">{{product.normal}}</view>	
				<view class="num">x{{product.num}}</view>
			</view>
			<view class="price">¥{{product.price}}</view>
		</view>
		<view class="infor-wrapper">
			<view class="infor-item border-bottom">
				<view class="title">物流单号： </view>
				<input type="text" v-model="expressNo" placeholder="请填写" />
			</view>
			<view class="infor-item">
				<view class="title">物流公司</view>
				<picker class="picker-wrapper" :value="expressIndex" :range="expressList" :range-key="'value'" @change="bindExpressPickerChange">
					<view class="picker">
						<view class="text" :class="{'placehol': !expressIndex}">{{expressList[expressIndex].value || '请选择'}}</view>
						<image src="/static/next06.png" class="icon"></image>	
					</view>
				</picker>
			</view>
		</view>
		<view class="img-wrapper">
			<view class="title">上传凭证</view>
			<view class="img-list">
				<view class="img-item" v-for="(image, index) in images" :key="index">
					<view class="delet" @click="handleCancel(index)">-</view>
					<image :src="image" mode="aspectFill" class="img"></image>
				</view>
				<view class="img-item btn" @click="handleUploadSingle">
					<image src="/static/upload02.png" class="img"></image>
					<text class="desc">上传凭证\n（最多6张）</text>
				</view>
			</view>
		</view>
		<button type="default" :disabled="flag" class="bottom-btn" @click="submit">提交</button>
	</view>
</template>

<script>
	import { frontDetail, memberSubmitExpress } from '@/api/order.js'
	import upload from '@/mixins/upload.js'
	export default {
		mixins: [upload],
		data() {
			return {
				orderId: '',
				expressNo: '',
				details: {
					orderRefund: {}
				},
				expressNo: '',
				expressIndex: '',
				expressList: [
					{
					  value: '邮政',
					  label: '邮政'
					}, {
					  value: '中通',
					  label: '中通'
					}, {
					  value: '圆通',
					  label: '圆通'
					}, {
					  value: '申通',
					  label: '申通'
					}, {
					  value: '韵达',
					  label: '韵达'
					}, {
					  value: '顺丰',
					  label: '顺丰'
					}, {
					  value: '汇通',
					  label: '汇通'
					}, {
					  value: '天天',
					  label: '天天'
					}, {
					  value: '优速',
					  label: '优速'
					}
				]
			}
		},
		onLoad(option) {
			this.orderId = option.orderId
			this.getDetails()
		},
		methods: {
			submit() {
				if (!this.expressNo) {
					uni.showToast({
						title: '请填写物流单号',
						icon: 'none',
						duration: 2000
					})
					return
				}
				if (!this.expressIndex) {
					uni.showToast({
						title: '请选择物流公司',
						icon: 'none',
						duration: 2000
					})
					return
				}
				const imagesStr = this.images.join(',')
				const data = {
				  refundId: this.details.orderRefund.id,
				  express: this.expressList[this.expressIndex].value,
				  expressNo: this.expressNo,
				  images: imagesStr
				}
				console.log('data',data)
				this.flag = true
				memberSubmitExpress(data).then(respanse => {
					uni.showToast({
						title: '提交成功！',
						icon: 'success',
						duration: 2000
					})
					let pages = getCurrentPages();  //获取所有页面栈实例列表
					let nowPage = pages[ pages.length - 1];  //当前页页面实例
					let prevPage = pages[ pages.length - 2 ];  //上一页页面实例
					prevPage.$vm.isOrderHandle = true // 监听是否选择地址
					setTimeout(() => {
						uni.navigateBack()
					}, 2000)
				}).catch(err => {
					this.flag = false
				})
			},
			
			getDetails() {
				const data = {
				  orderId: this.orderId
				}
				frontDetail(data).then(respanse => {
					this.details = respanse.result
				})
			},
			
			bindExpressPickerChange: function(e) {
				this.expressIndex = e.target.value
			}
		}
	}
</script>

<style lang="scss" scoped>
	.border-bottom{
		&::after{
			left: 20rpx;
			right: 20rpx;
		}
	}
	.address-wrapper{
		position: relative;
		padding: 34rpx 22rpx 0 25rpx;
		margin: 22rpx 25rpx 0;
		box-sizing: border-box;
		background: #FFFFFF;
		border-radius: 10rpx;
		overflow: hidden;
		.address{
			line-height: 46rpx;
			font-size: 36rpx;
			font-weight: bold;
			color: #000000;
		}
		.name-tel{
			padding-bottom: 34rpx;
			margin-top: 16rpx;
			line-height: 34rpx;
			font-size: 24rpx;
			color: #666666;
		}
		.time-wrapper{
			position: relative;
			display: flex;
			justify-content: space-between;
			padding-right: 34rpx;
			line-height: 117rpx;
			.title{
				font-size: 36rpx;
				font-weight: bold;
				color: #000000;
			}
			.time{
				font-size: 28rpx;
				color: #000000;
			}
		}
	}
	.product{
		display: flex;
		padding: 36rpx 23rpx 33rpx 32rpx;
		margin: 30rpx 25rpx 0;
		background-color: #fff;
		border-radius: 10rpx;
		overflow: hidden;
		.img{
			width: 156rpx;
			height: 156rpx;
			border-radius: 10rpx;
			background-color: #F5F5F5;
		}
		.text{
			flex: 1;
			padding-top: 7rpx;
			margin-left: 39rpx;
			overflow: hidden;
			.name{
				line-height: 38rpx;
				font-size: 28rpx;
				font-weight: bold;
				color: #080808;
			}
			.specifications{
				margin-top: 6rpx;
				line-height: 32rpx;
				font-size: 22rpx;
				color: #818181;
			}
			.num{
				margin-top: 19rpx;
				line-height: 38rpx;
				font-size: 28rpx;
				color: #000000;
			}
		}
		.price{
			line-height: 38rpx;
			font-size: 30rpx;
			font-weight: bold;
			color: #080808;
		}
	}
	.infor-wrapper{
		margin: 20rpx 25rpx 0;
		background-color: #fff;
		border-radius: 10rpx;
		overflow: hidden;
		.infor-item{
			position: relative;
			display: flex;
			.title{
				padding-left: 28rpx;
				line-height: 84rpx;
				font-size: 28rpx;
				color: #333333;
			}
			input{
				flex: 1;
				padding-left: 10rpx;
				height: 84rpx;
				font-size: 28rpx;
				color: #333333;
			}
			.picker-wrapper{
				flex: 1;
				.picker{
					display: flex;
					align-items: center;
					flex: 1;
					height: 84rpx;
					line-height: 84rpx;
					text-align: right;
					font-size: 28rpx;
					color: #333333;
					.text{
						flex: 1;
						margin-right: 28rpx;
						&.placehol{
							color: #999999;
						}
					}
					.icon{
						margin-right: 28rpx;
						width: 16rpx;
						height: 29rpx;
					}
				}
			}
		}
	}
	.amount-wrapper{
		padding: 22rpx 20rpx 22rpx 25rpx;
		line-height: 38rpx;
		font-size: 28rpx;
		color: #333333;
		.oran{
			padding-left: 10rpx;
			color: #EA5D2E;
		}
	}
	.amount-input{
		position: relative;
		input{
			display: block;
			padding: 0 20rpx 0 25rpx;
			width: 100%;
			height: 84rpx;
			box-sizing: border-box;
			font-size: 26rpx;
			color: #333;
		}
		
	}
	.img-wrapper{
		padding: 19rpx 0 8rpx 24rpx;
		margin: 20rpx 25rpx 0;
		background-color: #fff;
		border-radius: 10rpx;
		.title{
			margin-bottom: 23rpx;
			height: 38rpx;
			line-height: 38rpx;
			font-size: 28rpx;
			color: #333333;
		}
		.img-list{
			display: flex;
			flex-wrap: wrap;
			.img-item{
				position: relative;
				margin: 0 35rpx 30rpx 0;
				width: 160rpx;
				height: 160rpx;
				.img{
					width: 100%;
					height: 100%;
				}
				.delet{
					position: absolute;
					right: -20rpx;
					top: -20rpx;
					width: 50rpx;
					height: 50rpx;
					line-height: 50rpx;
					text-align: center;
					font-size: 30rpx;
					color: #fff;
					background: linear-gradient(90deg, #EB7C3F, #EA5D2E);
					border-radius: 50%;
				}
				.desc{
					position: absolute;
					left: 0;
					right: 0;
					top: 81rpx;
					line-height: 22rpx;
					text-align: center;
					font-size: 20rpx;
					color: #999999;
				}
			}
		}
	}
	.bottom-btn{
		display: block;
		margin: 49rpx auto 0;
		width: 690rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		font-size: 32rpx;
		color: #fff;
		background: linear-gradient(90deg, #EB7C3F, #EA5D2E);
		border-radius: 45px;
	}
</style>
